Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

240
Views
how does [len] became property of arr i.e. (Number(arr[len]) in the following code

i am unable to understand that how (Number(arr[len]) is composed. is [len] made the property of arr.

function arrayMax(arr) {
      var len = arr.length, max = -Infinity;
      while (len--) {
        if (Number(arr[len]) > max) {
          max = Number(arr[len]);
        }
      }
      return max;
    };
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This is probably some attempt at a super efficient way of getting the max value in a array.

len variable is badly named in all fairness. It should have been labeled index.

function arrayMax(arr) {
  var index = arr.length, max = -Infinity;
  while (index--) {
    if (Number(arr[index]) > max) {
      max = Number(arr[index]);
    }
  }
  return max;
};

And arr[index] gets the value at the specified index.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array#access_an_array_item_by_its_index

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!